Why are use the SQL CHECK Constraint in the database at table creation?
Why are use the SQL CHECK Constraint in the database at table creation?
Hi, my self Ravi Vishwakarma. I have completed my studies at SPICBB Varanasi. now I completed MCA with 76% form Veer Bahadur Singh Purvanchal University Jaunpur.
SWE @ MindStick | Software Engineer | Web Developer | .Net Developer | Web Developer | Backend Engineer | .NET Core Developer
Ashutosh Kumar Verma
27-Sep-2021SQL Check Constraint:
CHECK constraint is used to give a limit for the values to be passed on the column.
Data is inserted on the column according to the condition on which the CHECK constraint is given. A check constraint is used in SQL server allow you to specify condition on each row in a table.
CHECK constraints are column-level (single column) and table-level (multiple columns).
Check constraint is create two times, first when database table is created and other is alter table in exists table in database
1- SQL Check Constraint on table create:
The following SQL creates a Check constraint on the 'Age' column when the 'Student' table is created. The Check constraint ensures that the age of a Student must be 18, or older:
Check constraint on multiple columns in a table
2- SQL Check Constraint on created table:
The following SQL creates a Check Constraint on student Age in “Student” table which is created in database. Here the Check Constraint is used with SQL ALTER command. Ex- for single column in table,
For multiple columns of a table,
In the above Student table the records entered in which stuAge must be 18 or above and stuID is more than 3.
Drop Check Constraint:
To Drop a created Check Constraint in table, use the following SQL statement,
Other one is-